<!DOCTYPE html	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="/template/template_layout_lrt.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<style>
.ui-button, .ui-button span, button.ui-button.ui-state-default span,
	.ui-button.ui-state-default span {
	font-weight: normal
}
</style>
	</ui:define>
	<ui:define name="top-box-tools">
		<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
			<p:commandButton value="是" type="button"
				styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
			<p:commandButton value="否" type="button"
				styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
		</p:confirmDialog>
		<h:form id="btnForm">
			<p:growl id="msgs" showDetail="true" />
			<p:toolbar id="btnBar" rendered="#{s:hasPermission(session,'xtsz_xtqx_zzjg_xjbm') or
			s:hasPermission(session,'xtsz_xtqx_zzjg_xzyg') or 
			s:hasPermission(session,'xtsz_xtqx_zzjg_bjbm') or 
			s:hasPermission(session,'xtsz_xtqx_zzjg_bjyg') or 
			s:hasPermission(session,'xtsz_xtqx_zzjg_sc')}">
				<f:facet name="left">
					<p:commandButton icon="fa fa-plus" value="新建部门" style="margin-right:10px"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_zzjg_xjbm')}"
						disabled="#{orgController.currentDept==null}" update="cgform :cgform:deptNo"
						oncomplete="PF('createDeptDialog').show()"
						actionListener="#{orgController.preCreateDept()}" />
					<p:commandButton icon="fa fa-user-plus" value="新增员工" style="margin-right:10px"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_zzjg_xzyg')}"
						disabled="#{orgController.currentDept==null}"
						update=":crform:personnelInfopg :crform:createPersonToBar :crform:perNo :rightForm:plist"
						oncomplete="PF('createUserDialog').show()"
						actionListener="#{orgController.preCreatePerson()}" />
					<p:commandButton icon="fa fa-pencil" value="编辑部门" style="margin-right:10px"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_zzjg_bjbm')}"
						disabled="#{orgController.currentDept==null}" update="cgform"
						oncomplete="PF('createDeptDialog').show()" 
						actionListener="#{orgController.preEditDept()}"/>
					<p:commandButton icon="fa fa-pencil" value="编辑员工"  style="margin-right:10px"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_zzjg_bjyg')}"
						disabled="#{orgController.currentPerson==null}"
						update="editform:editInfopg editform:editPersonToBar changeDeptform:deptTree"
						actionListener="#{orgController.updateDeptTree}"
						oncomplete="PF('editUserDialog').show()" />
					<p:commandButton icon="fa fa-trash-o" value="删除" style="margin-right:10px"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_zzjg_sc')}"
						disabled="#{orgController.currentPerson==null &amp;&amp; orgController.currentDept==null}"
						update=":leftForm:tree :rightForm:plist :btnForm:btnBar :btnForm:msgs"
						actionListener="#{orgController.delete()}">
						<p:confirm header="提示" message="确定删除选中的记录吗?" icon="ui-icon-alert" />
					</p:commandButton>
				</f:facet>
			</p:toolbar>
		</h:form>
	</ui:define>
	<ui:define name="left-box-title" style="border:0">
		组织机构树
	</ui:define>
	<ui:define name="left-box-body">
		<h:form id="leftForm">
			<p:panel style="border:0;width:98%">
				<p:tree value="#{orgController.root}" var="node" dynamic="true"
					id="tree" widgetVar="tree" animate="true" selectionMode="single" style="border:0">
					<p:ajax event="expand" update="tree" listener="#{orgController.onNodeExpand}" />
					<p:ajax event="select" listener="#{orgController.onNodeSelect}"
						update=":btnForm:btnBar :rightForm:plist :cgform:createDeptToBar :editform:editPersonToBar" />
					<p:ajax event="unselect" listener="#{orgController.onNodeUnSelect}"
						update=":btnForm:btnBar :rightForm:plist :cgform:createDeptToBar :editform:editPersonToBar" />
					<p:treeNode type="dept" icon="fa fa-home">
						<h:outputText value="#{node}" />
					</p:treeNode>
					<p:treeNode type="personnel" icon="fa fa-user">
						<h:outputText value="#{node}" />
					</p:treeNode>
				</p:tree>
			</p:panel>
		</h:form>
	</ui:define>
	<ui:define name="right-box-title">
		员工信息列表
	</ui:define>
	<ui:define name="right-box-body">
		<h:form id="rightForm">
			<p:dataTable var="pebCurrent" id="plist" value="#{orgController.personnels}" rowKey="#{pebCurrent.id}"
				widgetVar="plist" emptyMessage="无记录" style="text-align:center">
				<p:column headerText="用户名" style="width:20%">
					<h:outputText value="#{pebCurrent.code}" />
				</p:column>
				<p:column headerText="姓名" style="width:10%">
					<h:outputText value="#{pebCurrent.name}" />
				</p:column>
				<p:column headerText="状态" style="width:10%">
					<h:outputText rendered="#{pebCurrent.locked}" style="color:red" value="锁定" />
					<h:outputText rendered="#{!pebCurrent.locked}" value="正常" />
				</p:column>
				<p:column headerText="电话" style="width:15%">
					<h:outputText value="#{pebCurrent.telephone}" />
				</p:column>
				<p:column headerText="地址" style="width:20%">
					<h:outputText value="#{pebCurrent.address}" />
				</p:column>
				<p:column headerText="操作" style="width:25%">
					<p:commandButton icon="fa fa-pencil" value="密码重置"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_zzjg_mmzz')}"
						actionListener="#{orgController.preResetPassword(pebCurrent.code)}"
						oncomplete="PF('resetPasswordDialog').show()" update="resetPwdForm:resetPwdpg" />
					<p:commandButton update="plist"
						actionListener="#{orgController.unLockPerson(pebCurrent)}"
						rendered="#{pebCurrent.locked}" icon="fa fa-unlock" value="解锁">
						<p:confirm header="提示" message="确定解除当前用户吗?" icon="ui-icon-alert" />
					</p:commandButton>
				</p:column>
			</p:dataTable>
		</h:form>
		<!-- 编辑员工 -->
		<p:dialog widgetVar="editUserDialog"  id="editUserDialog" header="编辑员工信息" closable="false"
			resizable="false" draggable="false" modal="true" width="430"
			height="350">
			<h:form id="editform">
				<p:toolbar id="editPersonToBar">
					<f:facet name="left">
						<p:commandButton value="保存" icon="ui-icon-disk" id="saveEditPerBtn"
							update=":leftForm:tree :btnForm:btnBar  :btnForm:msgs :rightForm:plist"
							oncomplete="PF('editUserDialog').hide()"
							disabled="#{!orgController.checkStatus}"
							actionListener="#{orgController.savePerson()}" />
						<p:commandButton icon="ui-icon-cancel" value="取消" type="button"
							onclick="PF('editUserDialog').hide()" style="margin-left:5px" />
					</f:facet>
				</p:toolbar>
				<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
				<p:message for="newName" display="text" />
				<p:panelGrid id="editInfopg" columns="2" cellpadding="4"
					style="width:100%;text-align:center">
					<h:outputText value="用户名:" />
					<p:inputText disabled="true" value="#{orgController.currentPerson.code}" />
					<h:outputText value="姓名:" />
					<p:inputText value="#{orgController.currentPerson.name}" id="newName">
						<p:ajax event="blur" update="editform:saveEditPerBtn"
							listener="#{orgController.valdateEditPerson(orgController.currentPerson)}" />
					</p:inputText>
					<h:outputText value="所属部门:" />
					<p:inputText value="#{orgController.currentPerson.group.name}" id="ownGroup" onclick="PF('deptDialog').show()" />
					<h:outputText value="电话:" />
					<p:inputText value="#{orgController.currentPerson.telephone}" />
					<h:outputText value="序号:" />
					<p:inputText value="#{orgController.currentPerson.orderNo}" />
					<h:outputText value="地址:" />
					<p:inputText value="#{orgController.currentPerson.address}" />
					<h:outputText value="角色:" />
					<p:selectManyCheckbox id="roles" value="#{orgController.selectedRoles}" layout="grid" columns="3">
				        <f:selectItems value="#{orgController.roles}" var="r" itemLabel="#{r.name}" itemValue="#{r.id}" />
				    </p:selectManyCheckbox>
				</p:panelGrid>
			</h:form>
		</p:dialog>
		<p:dialog widgetVar="resetPasswordDialog" id="resetPasswordDialog" header="密码重置" closable="true" resizable="false"
			draggable="false" modal="true" width="600px" height="200px">
			<p:layout style="width:580px;height:180px">
				<p:layoutUnit position="center">
					<h:form id="resetPwdForm">
						<p:toolbar>
							<f:facet name="left">
								<p:commandButton icon="ui-icon-disk" value="保存" oncomplete="PF('resetPasswordDialog').hide()"
									actionListener="#{orgController.updatePwd}" style="margin-left:5px" />
								<p:commandButton icon="ui-icon-cancel" value="取消"
									style="margin-left:5px" onclick="PF('resetPasswordDialog').hide()" />
							</f:facet>
						</p:toolbar>
						<p:panelGrid id="resetPwdpg" columns="2" cellpadding="8" style="width:100%;text-align:center">
							<h:outputText value="新密码:" />
							<p:password id="pwd3" style="width:100%"
								value="#{orgController.newPwd}" feedback="true" inline="true"
								promptLabel="输入密码" weakLabel="弱" goodLabel="中" strongLabel="强" />
							<h:outputText value="新密码确认:" />
							<p:password id="pwd4" style="width:100%" value="#{orgController.newPwd1}" />
						</p:panelGrid>
					</h:form>
				</p:layoutUnit>
				<p:layoutUnit position="east" header="密码要求" size="40%">
					1、密码的长度不小于8位<br />
					2、密码不能与旧密码相同<br />
					3、密码不能与用户名相同<br /> 
					4、密码至少为字符、数字和符号其中两种组合
				</p:layoutUnit>
			</p:layout>
		</p:dialog>
		<p:dialog widgetVar="createDeptDialog" id="createDeptDialog" header="部门信息" closable="false"
			resizable="false" draggable="false" modal="true" width="350" height="350">
			<h:form id="cgform">
				<p:toolbar id="createDeptToBar">
					<f:facet name="left">
						<p:commandButton value="保存" icon="ui-icon-disk" id="saveDeptBtn"
							update=":leftForm:tree :btnForm:btnBar :btnForm:msgs :rightForm:plist"
							oncomplete="PF('createDeptDialog').hide()" actionListener="#{orgController.saveDept()}"
							disabled="#{!orgController.checkStatus}" style="margin-left:10px" />
						<p:commandButton icon="ui-icon-cancel" value="取消" type="button" onclick="PF('createDeptDialog').hide()" />
					</f:facet>
				</p:toolbar>
				<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
				<p:message for="deptName" display="text" />
				<p:panelGrid id="deptInfopg" columns="2" cellpadding="4" style="width:100%;text-align:center">
					<h:outputText value="部门名称:" />
					<p:inputText value="#{orgController.currentDept.name}" id="deptName">
						<p:ajax event="blur" update="cgform:saveDeptBtn" listener="#{orgController.valdateDept(orgController.currentDept)}" />
					</p:inputText>
					<h:outputText value="负责人:" />
					<p:inputText value="#{orgController.currentDept.principal}" />
					<h:outputText value="电话:" />
					<p:inputText value="#{orgController.currentDept.telephone}" />
					<h:outputText value="类型:" />
					<p:selectOneMenu value="#{orgController.deptType}" style="width:80%">
						<f:selectItem itemLabel="" itemValue="" />
						<f:selectItems value="#{orgController.allDeptType}" />
						<!-- <f:selectItem itemLabel="#{ManagementUnitEnum.DESORG.name}" itemValue="#{ManagementUnitEnum.DESORG.getType()}" />
						<f:selectItem itemLabel="#{ManagementUnitEnum.SUBCOMPANY.name}" itemValue="#{ManagementUnitEnum.SUBCOMPANY.getType()}" />
						<f:selectItem itemLabel="#{ManagementUnitEnum.ENTERPISE.name}" itemValue="#{ManagementUnitEnum.ENTERPISE.getType()}" /> -->
					</p:selectOneMenu>
					<h:outputText value="序号:" />
					<p:inputText value="#{orgController.currentDept.sno}" id="deptNo" />
				</p:panelGrid>
			</h:form>
		</p:dialog>

		<p:dialog widgetVar="createUserDialog" header="新建员工信息" closable="false" resizable="true"
			draggable="false" modal="true" width="400" height="380">
			<h:form id="crform">
				<p:toolbar id="createPersonToBar">
					<f:facet name="left">
						<p:commandButton value="保存" icon="ui-icon-disk" id="savePerBtn"
							update=":leftForm:tree :btnForm:btnBar  :btnForm:msgs :rightForm:plist"
							oncomplete="PF('createUserDialog').hide()" actionListener="#{orgController.savePerson()}"
							disabled="#{!orgController.checkStatus}" />
						<p:commandButton icon="ui-icon-cancel" value="取消" type="button"
							onclick="PF('createUserDialog').hide()" style="margin-left:5px" />
					</f:facet>
				</p:toolbar>
				<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
				<p:message for="name" display="text" />
				<p:message for="code" display="text" />
				<p:panelGrid id="personnelInfopg" columns="2" cellpadding="4" style="width:100%;text-align:center">
					<h:outputText value="用户名:" />
					<p:inputText value="#{orgController.currentPerson.code}" id="code">
						<p:ajax event="blur" update="crform:savePerBtn"
							listener="#{orgController.valdatePerson(orgController.currentPerson)}" />
					</p:inputText>
					<h:outputText value="姓名:" />
					<p:inputText value="#{orgController.currentPerson.name}" id="name">
						<p:ajax event="blur" update="crform:savePerBtn"
							listener="#{orgController.valdatePerson(orgController.currentPerson)}" />
					</p:inputText>
					<h:outputText value="电话:" />
					<p:inputText value="#{orgController.currentPerson.telephone}" />
					<h:outputText value="序号:" />
					<p:inputText value="#{orgController.currentPerson.orderNo}" id="perNo" />
					<h:outputText value="地址:" />
					<p:inputText value="#{orgController.currentPerson.address}" />
					<h:outputText value="角色:" />
					<p:selectManyCheckbox id="roles" value="#{orgController.selectedRoles}" layout="grid" columns="3">
				        <f:selectItems value="#{orgController.roles}" var="r" itemLabel="#{r.name}" itemValue="#{r.id}" />
				    </p:selectManyCheckbox>
					<h:outputText style="color:red" value="注：" />
					<h:outputText style="color:red" value="初始密码为【Nfdwbhc@36621978】" />
				</p:panelGrid>
			</h:form>
		</p:dialog>
		
		<p:dialog widgetVar="deptDialog" header="选择新的部门" closable="false"
			resizable="false" draggable="false" modal="true" width="450" height="600">
			<h:form id="changeDeptform">
				<p:toolbar>
					<f:facet name="left">
						<p:commandButton value="确定" icon="ui-icon-disk"
							oncomplete="PF('deptDialog').hide()" update="editform:ownGroup"
							actionListener="#{orgController.changeDept()}" />
						<p:commandButton icon="ui-icon-cancel" value="关闭" type="button"
							onclick="PF('deptDialog').hide()" style="margin-left:5px" />
					</f:facet>
				</p:toolbar>
				<p:tree value="#{orgController.deptRoot}" var="node" dynamic="true"
					selectionMode="single" id="deptTree" widgetVar="deptTree"
					animate="true" style="border:0">
					<p:ajax event="expand" update="deptTree" listener="#{orgController.onDeptNodeExpand}" />
					<p:ajax event="select" listener="#{orgController.onDeptNodeSelect}" />
					<p:treeNode type="dept" icon="fa fa-home">
						<h:outputText value="#{node}" />
					</p:treeNode>
					<p:treeNode type="default" icon="fa fa-home">
						<h:outputText value="#{node}" />
					</p:treeNode>
				</p:tree>
			</h:form>
		</p:dialog>
	</ui:define>
</ui:composition>
